<?php

/*
 *    This file is part of the module OxProbs for OXID eShop Community Edition.
 *
 *    The module OxProbs for OXID eShop Community Edition is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    The module OxProbs for OXID eShop Community Edition is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with OXID eShop Community Edition.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @link   https://code.google.com/p/oxprobs/
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 * 
 * $Id: shippinghelper.php 69 2011-12-18 09:48:09Z jobarthel@gmail.com $
 *
 */
 
class shippinghelper extends shippinghelper_parent
{
    protected $_sThisTemplate = "shippinghelper/shippinghelper.tpl";
    public function render()
    {
        parent::render();
        $oSmarty = oxUtilsView::getInstance()->getSmarty();
        $oSmarty->assign( "oViewConf", $this->_aViewData["oViewConf"]);
        $oSmarty->assign( "shop", $this->_aViewData["shop"]);

        include "config.inc.php";
        
        $sSql = 'SELECT '
            . 'IF(o.oxdelcity = \'\', '
                . 'CONCAT_WS(\'|\', '
                    . 'u.oxsal, CONCAT(o.oxbillfname, \' \', o.oxbilllname), o.oxbillcompany, o.oxbillstreet, o.oxbillstreetnr, '
                    . 'o.oxbillzip, o.oxbillcity, c.oxtitle, u.oxcustnr, o.oxordernr, '
                    . 'IF(o.oxpaymenttype = \'oxidcashondel\', \'1\', \'0\'), IF(o.oxpaymenttype = \'oxidcashondel\', o.oxtotalordersum, \'0\')), '
                . 'CONCAT_WS(\'|\', '
                    . 'u.oxsal, CONCAT(o.oxdelfname, \' \', o.oxdellname), o.oxdelcompany, o.oxdelstreet, o.oxdelstreetnr, '
                    . 'o.oxdelzip, o.oxdelcity, c.oxtitle, u.oxcustnr, o.oxordernr, '
                    . 'IF(o.oxpaymenttype = \'oxidcashondel\', \'1\', \'0\'), IF(o.oxpaymenttype = \'oxidcashondel\', o.oxtotalordersum, \'0\')) ) '
                .'AS oxaddress '    
            . 'FROM oxorder o, oxuser u, oxcountry c '
            . 'WHERE '
                . 'u.oxid = o.oxuserid '
                . 'AND c.oxid = IF(o.oxdelcity = \'\', o.oxbillcountryid, o.oxdelcountryid) '
                . 'AND (o.oxpaymenttype in (\'oxidcashondel\', \'oxidinvoice\') '
                . 'OR DATE(o.oxpaid) != \'0000-00-00\') '
                . 'AND o.oxsenddate = \'0000-00-00\' '
                . 'AND o.oxstorno != 1';

        $i = 0;
        $aOrders = array();

        $rs = oxDb::getDb(true)->Execute($sSql);
        /*echo '<pre>';
        echo $sSql;
        echo '</pre>';*/
        while (!$rs->EOF) {
            array_push($aOrders, $rs->fields);
            $rs->MoveNext();
        }

         $oSmarty->assign("aOrders",$aOrders);

         return $this->_sThisTemplate;
   }
 }
?>